import axios from '../utils/axios'

import md5 from 'js-md5'; //md5加密
// import axios from 'axios'

// /**
//  * 反向字符串拼接
//  * @param json
//  * @returns {string}
//  */
export function valueReverse(json) {
    let arrays = "myistest0000";
    for (var key in json) {
        if (key == "signature") {
            continue;
        }
        arrays += "," + key;
    }
    if (arrays == "myistest0000") {
        return;
    }

    let array = arrays.split(",");
    array.sort().reverse();
    var jsonStr = "";
    for (var i in array) {
        if ((array[i] == "myistest0000" || json[array[i]] == "" || json[array[i]] == undefined) && json[array[i]] !=
            0) {
            continue;
        }
        // jsonStr += json[array[i]];
        if (typeof (json[array[i]]) == "object") {
            jsonStr += JSON.stringify(json[array[i]]);
        } else {
            jsonStr += json[array[i]];
        }
    }
    return jsonStr;
}



export function uploadFile(params) {
    const formData = new FormData();
    formData.append('file', params);
    formData.append('token', localStorage.getItem('token'));
    formData.append('signature', md5(md5(valueReverse(formData))));
    return axios.post('/file/upload', formData)

}
